package org.springblade.modules.notice.enums.placeholder;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springblade.modules.notice.constant.RepairVariableConstant;
import org.springblade.modules.notice.vo.CommonEnumInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author ysq
 * @Date 2024/11/21
 * @Description 维修变量
 */
@Getter
@AllArgsConstructor
public enum RepairVariable implements VariableEnum {

	PLAN_ID(0, "planId", "工单ID", true, RepairVariableConstant.WORKER_INFO),

	PROJECT_NAME(1, "projectName", "项目名称", true, RepairVariableConstant.WORKER_INFO),

	ELEVATOR_NAME(2, "elevatorAddress", "电梯名称", true, RepairVariableConstant.WORKER_INFO),

	USER_ASSIGN_TIME(3, "userAssignTime", "人员指派时间", true, RepairVariableConstant.WORKER_EXT_INFO),

	REPAIR_DESC(4, "repairDesc", "故障描述", true, RepairVariableConstant.WORKER_EXT_INFO),

	ESTIMATED_END_TIME(5, "estimatedEndTime", "预计结束时间", true, RepairVariableConstant.WORKER_INFO),

	EXECUTOR(6, "executor", "任务执行人", true, RepairVariableConstant.EXECUTOR),

	CREATE_TIME(7, "createTime", "工单创建时间", true, RepairVariableConstant.WORKER_INFO),

	APPROVAL_FEEDBACK(8, "approvalFeedback", "审批反馈", true, RepairVariableConstant.WORKER_APPROVE),

	FIRST_SIGN_IN_USER(9, "firstSignInUser", "首个签到人", true, RepairVariableConstant.FIRST_SIGN_INFO),

	FIRST_SIGN_IN_TIME(10, "firstSignInTime", "工单签到时间", true, RepairVariableConstant.WORKER_EXT_INFO),

	ELEVATOR_ID(11, "elevatorId", "电梯ID", false, RepairVariableConstant.WORKER_INFO),

	APPROVE_ID(12, "approveId", "审批ID", false, RepairVariableConstant.WORKER_APPROVE),

	MAL_PHONE(13, "malPhone", " 报障人电话", true, RepairVariableConstant.WORKER_EXT_INFO),

	NOT_SIGN_OUT_USER_NAMES(14, "notSignOutUserNames", "未签退人员名称", true, RepairVariableConstant.NOT_SIGN_OUT_USER_NAMES),

	FIRST_SIGN_OUT_TIME(15, "firstSignOutTime", "工单签退时间", true, RepairVariableConstant.FIRST_SIGN_OUT_INFO),

	FIRST_SIGN_OUT_USER_NAME(16, "firstSignOutUserName", "首个签退人", true, RepairVariableConstant.FIRST_SIGN_OUT_INFO),

	REPORTER(17, "reporter", "报障人", true, RepairVariableConstant.WORKER_EXT_INFO),

	PLAN_DATE(18, "planDate", "计划日期", true, RepairVariableConstant.WORKER_INFO),

	FAULT_PROBLEM(19, "faultProblem", "故障现象", true, RepairVariableConstant.FAULT_PROBLEM),

	PLAN_END_TIME(20, "planEndTime", "工单完成时间", true, RepairVariableConstant.WORKER_EXT_INFO),
	;

	/**
	 * 编码
	 */
	private final Integer code;

	/**
	 * 变量名称
	 */
	private final String var;

	/**
	 * 描述
	 */
	private final String desc;

	/**
	 * 是否显示
	 */
	private final Boolean isShow;

	/**
	 * sql
	 */
	private final String sql;

	/**
	 * 获取可选列表
	 * @return 可选列表
	 */
	public static List<CommonEnumInfo> getSelectList() {
		List<CommonEnumInfo> list = new ArrayList<>(16);
		for (RepairVariable value : RepairVariable.values()) {
			if (value.isShow) {
				list.add(new CommonEnumInfo(value.getCode(), String.format("%s: ${%s}", value.getDesc(), value.getVar())));
			}
		}
		return list;
	}

	/**
	 * 根据code获取变量名
	 * @param code
	 * @return
	 */
	public static String getVarByCode(Integer code) {
		for (RepairVariable value : RepairVariable.values()) {
			if (value.getCode().equals(code)) {
				return value.getVar();
			}
		}
		return null;
	}

	/**
	 * 根据变量名获取code
	 * @param var
	 * @return
	 */
	public static Integer getCodeByVar(String var) {
		for (RepairVariable value : RepairVariable.values()) {
			if (value.getVar().equals(var)) {
				return value.getCode();
			}
		}
		return null;
	}
}
